package com.hqyj.service.impl;

import com.hqyj.pojo.TbCar;
import com.hqyj.dao.TbCarMapper;
import com.hqyj.service.TbCarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 车辆表 服务实现类
 * </p>
 *
 * @author gp
 * @since 2021-09-25
 */
@Service
public class TbCarServiceImpl implements TbCarService {

    @Autowired
    private TbCarMapper carMapper;

    @Override
    public HashMap<String, Object> insertCar(TbCar tbCar) {
        HashMap<String,Object> map  = new HashMap<>();
        int num = carMapper.insert(tbCar);
        if(num>0){
            map.put("info","保存成功");
        }else{
            map.put("info","保存失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> updateCar(TbCar tbCar) {
        HashMap<String,Object> map  = new HashMap<>();
        //业主修改信息后，获取当前的时间确定为业主修改信息的时间
        tbCar.setUpdateTime(LocalDateTime.now());
//        LocalDateTime now = LocalDateTime.now();
//        System.out.println(now);
        int num = carMapper.updateById(tbCar);
        if(num>0){
            map.put("info","保存成功");
        }else{
            map.put("info","保存失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> deleteCar(Integer id) {
        HashMap<String,Object> map  = new HashMap<>();
        int num = carMapper.deleteById(id);
        if(num>0){
            map.put("info","删除成功");
        }else{
            map.put("info","删除失败");
        }
        return map;
    }

    @Override
    public List<TbCar> listCarByOwnerId(Integer ownerId) {
        List<TbCar> tbCars = carMapper.listCarByOwnerId(ownerId);
        return tbCars;
    }

    @Override
    public List<TbCar> listCar() {
        List<TbCar> tbCars = carMapper.selectList(null);
        return tbCars;
    }
}
